package com.ruoyi.operation.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.operation.domain.Restaurant;
import com.ruoyi.operation.service.IRestaurantService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
/**
 * 商户信息总表管理Controller
 *
 * @author yukuan
 * @date 2022-07-09
 */
@RestController
@RequestMapping("/restaurant")
public class RestaurantController extends BaseController
{
    @Autowired
    private IRestaurantService restaurantService;

    /**
     * 查询商户信息总表管理列表
     */
    @RequiresPermissions("operation:restaurant:list")
    @GetMapping("/list")
    public TableDataInfo list(Restaurant restaurant)
    {
        startPage();
        List<Restaurant> list = restaurantService.selectRestaurantList(restaurant);
        return getDataTable(list);
    }

    /**
     * 导出商户信息总表管理列表
     */
    @RequiresPermissions("operation:restaurant:export")
    @Log(title = "商户信息总表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Restaurant restaurant)
    {
        List<Restaurant> list = restaurantService.selectRestaurantList(restaurant);
        ExcelUtil<Restaurant> util = new ExcelUtil<Restaurant>(Restaurant.class);
        util.exportExcel(response, list, "商户信息总表管理数据");
    }

    /**
     * 获取商户信息总表管理详细信息
     */
    @RequiresPermissions("operation:restaurant:query")
    @GetMapping(value = "/{restaurantid}")
    public AjaxResult getInfo(@PathVariable("restaurantid") Long restaurantid)
    {
        return AjaxResult.success(restaurantService.selectRestaurantByRestaurantid(restaurantid));
    }
    @ResponseBody
    @GetMapping ("/query/{restaurantid}")
    public Restaurant getRestaurant(@PathVariable("restaurantid") String restaurantid){
        Restaurant restaurant=restaurantService.selectRestaurantByRestaurantid((long) Integer.parseInt(restaurantid));
        return restaurant;
    }

    @ResponseBody
    @PostMapping ("/add_rank/{restaurantid}")
    public Restaurant add_rank(@PathVariable("restaurantid") String restaurantid){
        Restaurant restaurant=restaurantService.selectRestaurantByRestaurantid((long) Integer.parseInt(restaurantid));
        restaurant.setEmptytablenum(restaurant.getEmptytablenum()+1);
        restaurantService.update_rank(restaurant);
        return restaurant;
    }

    @ResponseBody
    @PostMapping("/reduce_rank/{restaurantid}")
    public Restaurant reduce_rank(@PathVariable("restaurantid") String restaurantid){
        Restaurant restaurant=restaurantService.selectRestaurantByRestaurantid((long)Integer.parseInt(restaurantid));
        restaurant.setEmptytablenum(restaurant.getEmptytablenum()-1);
        restaurantService.update_rank(restaurant);
        return restaurant;
    }
    /**
     * 新增商户信息总表管理
     */
    @RequiresPermissions("operation:restaurant:add")
    @Log(title = "商户信息总表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Restaurant restaurant)
    {
        return toAjax(restaurantService.insertRestaurant(restaurant));
    }

    /**
     * 修改商户信息总表管理
     */
    @RequiresPermissions("operation:restaurant:edit")
    @Log(title = "商户信息总表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Restaurant restaurant)
    {
        return toAjax(restaurantService.updateRestaurant(restaurant));
    }

    /**
     * 删除商户信息总表管理
     */
    @RequiresPermissions("operation:restaurant:remove")
    @Log(title = "商户信息总表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{restaurantids}")
    public AjaxResult remove(@PathVariable Long[] restaurantids)
    {
        return toAjax(restaurantService.deleteRestaurantByRestaurantids(restaurantids));
    }
}
